package net.tycmc.cty.ctyms.timejob.iems.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.cty.ctyms.timejob.common.ConfigEnum;
import net.tycmc.cty.ctyms.timejob.iems.dao.VclParaFreqSetDAO;
import net.tycmc.cty.ctyms.timejob.iems.dao.VehicleInfoDAO;
/**
 * 设备参数频率设置Service
 * @author chengshichao
 * 创建时间：2013-3-22
 */
public class VclParaFreqSetService {
	
	private VclParaFreqSetDAO vclParaFreqSetDAO;
	
	private VehicleInfoDAO vclInfoDAO;

	/**
	 * @return the vclParaFreqSetDAO
	 */
	public VclParaFreqSetDAO getVclParaFreqSetDAO() {
		return vclParaFreqSetDAO;
	}

	/**
	 * @param vclParaFreqSetDAO the vclParaFreqSetDAO to set
	 */
	public void setVclParaFreqSetDAO(VclParaFreqSetDAO vclParaFreqSetDAO) {
		this.vclParaFreqSetDAO = vclParaFreqSetDAO;
	}

	/**
	 * @return the vclInfoDAO
	 */
	public VehicleInfoDAO getVclInfoDAO() {
		return vclInfoDAO;
	}

	/**
	 * @param vclInfoDAO the vclInfoDAO to set
	 */
	public void setVclInfoDAO(VehicleInfoDAO vclInfoDAO) {
		this.vclInfoDAO = vclInfoDAO;
	}

	/**
	 * 自动切换参数频率设置
	 */
	public void autoSwitchParaFreqSet(){
		//专有
		List<Map<String,Object>> listUDS = vclParaFreqSetDAO.getValidParaFreqUDS();
		autoSwitchParaFreqSet(listUDS, "0", ConfigEnum.ParaFreqUDS.getName());
		vclParaFreqSetDAO.updateChkStatusUDS();
		
		//公有
		List<Map<String,Object>> listPGN = vclParaFreqSetDAO.getValidParaFreqPGN();
		autoSwitchParaFreqSet(listPGN, "1", ConfigEnum.ParaFreqPGN.getName());
		vclParaFreqSetDAO.updateChkStatusPGN();
	}
	
	/**
	 * 自动切换参数频率设置
	 * @param list 设置频率的设备集合
	 * @param paramType 参数类型 ，0：专有      1：公有
	 * @param setVal 设置值
	 */
	public void autoSwitchParaFreqSet(List<Map<String,Object>> list,String paramType,String setVal){
		if(list.size()>0){
			for(Map<String,Object> map:list){
				List<Map<String,Object>> listVclInfo = new ArrayList<Map<String,Object>>();
				if(StringUtil.isNullOrEmpty(MapGetter.getString(map, "VclPFI_SetType"))){
					if(MapGetter.getString(map, "VclPFI_SetType").equals("0")){
						listVclInfo = vclInfoDAO.getVclsByVclType(MapGetter.getString(map, "VclPFI_SetObjID"));
					}else if(MapGetter.getString(map, "VclPFI_SetType").equals("1")){
						Map<String,Object> vclMap = new HashMap<String,Object>();
						vclMap.put("VehicleID", MapGetter.getString(map, "VclPFI_SetObjID"));
						listVclInfo.add(vclMap);
					}else{
						//暂不处理
						continue;
					}
				}else{
					//暂不处理
					continue;
				}
				vclParaFreqSetDAO.setTmnlFreqInfo(listVclInfo, paramType, setVal);
			}
		}else{
			//暂不处理
		}
	}
	
}
